/* 
 * Copyright (C) 2015 Vishal Gupta<ims.vishal@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

var app = {};

app.content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ac tempus libero. Praesent at lacinia urna, sed venenatis urna. Ut in porta leo, vel auctor est. Duis vitae facilisis felis. Nulla rutrum ultricies tincidunt. Sed non nibh vitae lectus mollis convallis in id lectus. Proin cursus erat ut ante cursus, nec facilisis neque congue. Fusce leo dui, ultricies ultrices ex non, rhoncus tincidunt quam. Proin et vehicula enim. Mauris porta, lectus vitae sagittis vestibulum, nisl enim faucibus neque, nec fermentum justo odio sit amet ligula. Sed orci diam, vulputate sed velit sed, auctor blandit leo. Aliquam posuere, turpis eu sollicitudin bibendum, orci massa pretium libero, vel eleifend lectus risus et metus. Nunc nibh lacus, gravida vel iaculis ac, vehicula nec nulla.';

app.states = {
    alert: function () {
        alert('test');
    },
    clearContent: function () {
        $('#content').text('');
        console.log('content was cleared');
        location.href = '#';
    },
    showContent: function () {
        $('#content').text(app.content);
    },
    usingParams: function () {
        var name = prompt('Please enter your name?');
        location.href = "#/dynamic/" + name;
    },
    dynamicParams: function () {
        $('#content').html('How are you <strong>' + this.params['name'] + '</strong>?');
    },
    multipleParams: function () {
        var param1 = prompt('Which is the largest planet of our solar system?').toUpperCase(),
                param2 = confirm('Are you sure ' + param1 + ' is the largest planet?');

        location.href = "#/dynamic/" + param1 + '/' + param2;
    },
    multipleDynamicParams: function () {
        if (this.params['param1'] === 'JUPITER' && this.params['param2'] === 'true') {
            $('#content').text('You answered it correct');
        } else {
            $('#content').text('Jupiter is the largest planet in our solar system');
        }
    }
};

app.routes = {
    '#/alert': app.states.alert,
    '#/showContent': app.states.showContent,
    '#/clearContent': app.states.clearContent,
    '#/using/param': app.states.usingParams,
    '#/dynamic/:name': app.states.dynamicParams,
    '#/using/multiple/param': app.states.multipleParams,
    '#/dynamic/:param1/:param2': app.states.multipleDynamicParams
};

$(function () {
    if (!Path)
        console.log('Path js not found');

    for (var i in app.routes)
        Path.map(i).to(app.routes[i]);

    Path.listen();
});
